package com.ganzalang.gmall.promotion.controller;

import com.ganzalang.gmall.promotion.dto.CartRuleContext;
import com.ganzalang.gmall.promotion.dto.CartRuleResult;
import com.ganzalang.gmall.promotion.dto.PromotionContext;
import com.ganzalang.gmall.promotion.dto.PromotionResult;
import com.ganzalang.gmall.promotion.service.CartRuleService;
import com.ganzalang.gmall.promotion.service.PromotionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @description: 购物车控制层
 * @author: Ganzalang
 * @Date 2022/4/12 11:10
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api/v1/cart")
public class CartController {

    private final PromotionService promotionService;
    private final CartRuleService cartRuleService;

    /**
     * 计算购物车的优惠
     *
     * @param context
     * @return
     */
    @PostMapping("/calculate")
    public CartRuleResult calculate(@RequestBody @Valid CartRuleContext context) {
        CartRuleResult result = cartRuleService.handle(context);
        return result;
    }

}
